osdep/unix/getroot: Fix potential underflow
authorLidong Chen <lidong.chen@oracle.com>
Wed, 29 Jan 2025 06:48:38 +0000 (06:48 +0000)
committerFelix Zielcke <fzielcke@z-51.de>
Thu, 3 Jul 2025 16:35:51 +0000 (18:35 +0200)
commit97e9e5803c9778b3bc3a7cc91c853f5e7ec2de13
treeeff0c772488ab67a30423b371105aa934e2975a1
parent0102b6b2c1e327e9912b0cb7db9ed25bf95f48f5
osdep/unix/getroot: Fix potential underflow

The entry_len is initialized in grub_find_root_devices_from_mountinfo()
to 0 before the while loop iterates through /proc/self/mountinfo. If the
file is empty or contains only invalid entries entry_len remains
0 causing entry_len - 1 in the subsequent for loop initialization
to underflow. To prevent this add a check to ensure entry_len > 0 before
entering the for loop.

Fixes: CID 473877
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
Gbp-Pq: Topic cve-2025-jan
Gbp-Pq: Name osdep-unix-getroot-Fix-potential-underflow.patch
grub-core/osdep/linux/getroot.c